<template>
	<view class="addDaili">
		<!-- <u-navbar
			title="新增代理商" 
			left-text="" 
			@leftClick="onClickBack"
			:placeholder="true"
			:fixed="true"
			:safeAreaInsetTop="true"
		></u-navbar> -->	
		<view class="bg-white padding">
			<view class="cu-steps">
				<view class="cu-item" :class="index>num?'':'text-blue'" v-for="(item,index) in numList" :key="index">
					<text class="num" :class="index==2?'err':''" :data-index="index + 1"></text> {{item.name}}
				</view>
			</view>
		</view>
		<view class="content">
			<u--form
				labelPosition="left"
				:model="formData"
				ref="form1" >
				<u-form-item
					label="登录账号"
					prop="account"
					borderBottom
					labelWidth="100"
					clearable
					ref="item1">
					<u--input v-model="formData.account" border="none" placeholder="请输入8~20位数字或字母"></u--input>
				</u-form-item>
				<u-form-item
					label="登录密码"
					prop="password"
					borderBottom
					labelWidth="100"
					clearable
					ref="item1">
					<u--input v-model="formData.password" :type="inputType" border="none" placeholder="请输入8~20位数字或字母"></u--input>
					<u-icon name="eye" color="#2979ff" slot="right" @click="seePwd"></u-icon>
				</u-form-item>
				<u-form-item
					label="代理商名称"
					prop="name"
					borderBottom
					labelWidth="100"
					clearable
					ref="item1">
					<u--input v-model="formData.name" border="none" placeholder="请输入代理商名称"></u--input>
				</u-form-item>
				<u-form-item
					label="绑定手机"
					prop="phone"
					borderBottom
					labelWidth="100"
					clearable
					ref="item1">
					<u--input v-model="formData.phone" border="none" placeholder="请输入手机号"></u--input>
				</u-form-item>
				
			</u--form>
		</view>
		<view class="m20">
			<u-button type="primary" text="下一步" @click="submit"></u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
export default {
	data() {
		return {
			numList: [{
				name: '基本信息'
			},  {
				name: '成本信息'
			}, ],
			num: 0,
			scroll: 0,
			formData: {
				account: '',
				password: '',
				name: '',
				phone: ''
			},
			inputType: 'text'
		}
	},
	methods: {
		// 返回页面
		onClickBack () {
			uni.navigateBack()
		},
		seePwd () {
			this.inputType === 'password'?this.inputType = 'text':this.inputType = 'password';
		},
		submit () {
			if (this.formData.account === '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请输入登录账号",
				})
				return
			}
			if (this.formData.password === '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请输入登录密码",
				})
				return
			}
			if (this.formData.phone === '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请输入业务员手机号",
				})
				return
			}
			if (this.formData.name === '') {
				this.$refs.uToast.show({
					type: 'default',
					title: '默认主题',
					message: "请输入业务员姓名",
				})
				return
			}
			this.sendData();

			
			
			// uni.request({
			// 	method:"GET",
			//     url: 'https://ynf.xxhf.cn/api/index/addagent_add',
			// 	data:{
			// 		agentid:uni.getStorageSync("YNF_INFO").user_id,username: this.formData.account,
			// 	nickname:this.formData.name,
			// 	password: this.formData.password,
			// 	truename: this.formData.name,
			// 	mobile: this.formData.phone},
			// 	header: {
			// 	    token: uni.getStorageSync('token')
			// 	},
			//     success: (res) => {
			// 		console.log(res)
			// 		if (res.data.code === 1) {
			// 			console.log('sssssssss');
			// 			uni.navigateTo({
			// 				url: "/pages/my/costchange?user_id="+res.data.data.id,
			// 			});
			// 		} else { 
			// 			uni.showToast({
			// 				icon: 'none',
			// 				title: res.data.msg
			// 			})
			// 		}
				 
			//     }
			// });
		
			// this.withdrawMoney()
	
		},
		async sendData () {
			this.list = []
			let params = {
				username: this.formData.account,
				nickname:this.formData.name,
				password: this.formData.password,
				truename: this.formData.name,
				mobile: this.formData.phone
			}
					
			const res = await this.$API({url: '/api/index/addagent_add',method:"GET", data: params})
			console.log(res.data.code);
			if (res.code === 1) {
				uni.navigateTo({
					url: "/pages/my/costchange?user_id="+res.data.id+'&type=add',
				});
			} else { 
				uni.showToast({
					icon: 'none',
					title: res.msg
				})
			}
		},
	}
}
</script>

<style lang="scss" scoped>
	.content {
		margin-top: 20rpx;
		background: #FFFFFF;
		padding: 0 20rpx;
	}
	.padding
	{
		padding: 6upx;
	}
</style>
